package com.dgut.doctorservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dgut.doctorservice.entity.MedecineInfo;
import com.dgut.doctorservice.entity.MedecineManager;
import com.dgut.doctorservice.mapper.MedecineManagerMapper;
import com.dgut.doctorservice.service.MedecineInfoService;
import com.dgut.doctorservice.service.MedecineManagerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dgut
 * @since 2021-09-11
 */
@Service
public class MedecineManagerServiceImpl extends ServiceImpl<MedecineManagerMapper, MedecineManager> implements MedecineManagerService {

    @Autowired
    MedecineInfoService medecineInfoService;

    @Override
    public Integer inputManager(String medecineId,Integer number) {
        QueryWrapper<MedecineInfo> wrapper=new QueryWrapper<>();
        MedecineInfo medecine = medecineInfoService.getById(medecineId);
        Integer flag=0;
        if (medecine!=null){
            medecine.setNumber(medecine.getNumber()+number);
            medecineInfoService.updateById(medecine);
        }
        return flag;
    }

    @Override
    public Integer outputManager(String medecineId,Integer number) {
        QueryWrapper<MedecineInfo> wrapper=new QueryWrapper<>();
        MedecineInfo medecine = medecineInfoService.getById(medecineId);
        Integer flag=0;
        if (medecine!=null){
            medecine.setNumber(medecine.getNumber()-number);
            medecineInfoService.updateById(medecine);
        }
        return flag;
    }
}
